<?php
class Z1thongbaosController extends AppController {

	var $name = 'Z1thongbaos';

	function index($user_id=null) {
		$this->Z1thongbao->recursive = 0;
		$this->set('z1thongbaos', $this->paginate(array('user_id'=>$user_id)));
        $this->set(compact('user_id'));
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid z1thongbao', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('z1thongbao', $this->Z1thongbao->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Z1thongbao->create();
			if ($this->Z1thongbao->save($this->data)) {
				$this->Session->setFlash(__('The z1thongbao has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The z1thongbao could not be saved. Please, try again.', true));
			}
		}
		$users = $this->Z1thongbao->User->find('list');
		$chucvs = $this->Z1thongbao->Chucv->find('list');
		$khoas = $this->Z1thongbao->Khoa->find('list');
		$this->set(compact('users', 'chucvs', 'khoas'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid z1thongbao', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Z1thongbao->save($this->data)) {
				$this->Session->setFlash(__('The z1thongbao has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The z1thongbao could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Z1thongbao->read(null, $id);
		}
		$users = $this->Z1thongbao->User->find('list');
		$chucvs = $this->Z1thongbao->Chucv->find('list');
		$khoas = $this->Z1thongbao->Khoa->find('list');
		$this->set(compact('users', 'chucvs', 'khoas'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for z1thongbao', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Z1thongbao->delete($id)) {
			$this->Session->setFlash(__('Z1thongbao deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Z1thongbao was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
